<template>
  <div class="app-container">
    <el-row :gutter="24" class="mb8">
      <el-col :span="24" style="text-align: right;">
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="$router.go(0)"
        >刷新</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-refresh"
          size="mini"
          @click="$router.go(-1)"
        >返回</el-button
        >
      </el-col>
    </el-row>
    <!-- 表格 -->
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        预览资讯图文
      </div>
      <div class="text item">
        <el-row :gutter="24">
          <el-col :lg="16" :xs="24">
            <el-image class="preview" :src="formData.cover" alt="">
              <div slot="error" class="image-slot">
                <i class="el-icon-picture-outline"></i>
              </div>
            </el-image>
            <div class="title">{{ formData.title }}</div>
            <el-row :gutter="24">
              <el-col :span="18" :xs="24">
                <div class="summary">{{ formData.summary }}</div>
              </el-col>
              <el-col :span="6" :xs="24">
                <el-button size="mini" class="viewBtn" type="primary" @click="viewDetails">查看详情</el-button>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getInformation } from "@/api/gwoper/news";

export default {
  name: "Preview",
  data() {
    return {
      formData: {
        id: null,
        title: "",
        lableId: "",
        contentType: "",
        content: null,
        showBeginTime: null,
        showEndTime: null,
        orderNo: null,
        cover: null,
        summary: null,
        onSell: 0, // 上下架（0-下架  1-上架）
        publishTime: null // 发布时间
      },
      newsDialogFu: false
    };
  },
  created() {
    this.formData.id = this.$route.query.id ? this.$route.query.id : null;
    if (this.formData.id) {
      this.getInfo();
    }
  },
  methods: {
    // 查看详情
    viewDetails() {
      let url = ""
      if(this.formData.contentType==0){
        url = this.formData.content
      }else if(this.formData.contentType==1){
        let {href} = this.$router.resolve({
          path: '/viewDetails',
          query: { id: this.formData.id }
        })
        url = href
      }
      console.log(url)
      window.open(url, '_blank')
    },
    // 获取图文详情
    getInfo() {
      getInformation(this.formData.id)
        .then(response => {
          console.log(response);
          if (response.code != 200) {
            return this.msgError(response.msg);
          }
          this.formData = response.data;
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>

<style lang="scss">
@import "@/assets/styles/card.scss";
.preview {
  position: relative;
  width: 100%;
  min-height: 150px;
  border: 1px solid #dcdfe6;
  .image-slot {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .el-icon-picture-outline:before {
      font-size: 50px;
      color: #dcdfe6;
    }
  }
}
.title {
  font-weight: bold;
  font-size: 20px;
  margin: 20px 0 10px;
}
.summary {
  font-size: 16px;
}
.el-col:nth-child(2) {
    min-height: 40px;
  .viewBtn {
    position: absolute;
    right: 12px;
    bottom: 0;
  }
}
</style>
